package com.ruibang.glass.material.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruibang.glass.common.constants.RedisKey;
import com.ruibang.glass.material.constant.MaterialWareHouseInTableNameCode;
import com.ruibang.glass.material.domain.req.MaterialInAndOutRecordReq;
import com.ruibang.glass.material.domain.req.MaterialRecordsReq;
import com.ruibang.glass.material.dto.MaterialRecordsDTO;
import com.ruibang.glass.material.entity.*;
import com.ruibang.glass.material.entity.bcp.MaterialBcpProductsInInfo;
import com.ruibang.glass.material.entity.bcp.MaterialBcpProductsOut;
import com.ruibang.glass.material.entity.cp.MaterialCPProductsInInfo;
import com.ruibang.glass.material.entity.cp.MaterialCPProductsOut;
import com.ruibang.glass.material.mapper.*;
import com.ruibang.glass.material.mapper.bcp.MaterialBcpProductsInInfoMapper;
import com.ruibang.glass.material.mapper.bcp.MaterialBcpProductsOutMapper;
import com.ruibang.glass.material.mapper.cp.MaterialCPProductsInInfoMapper;
import com.ruibang.glass.material.mapper.cp.MaterialCPProductsOutMapper;
import com.ruibang.glass.material.service.MaterialInAndOutRecordsService;
import com.ruibang.glass.material.service.bcp.MaterialBcpProductsInInfoService;
import com.teaming.cloud.framework2.autoconfigure.redis.RedisSingleService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 物料管理表 服务实现类
 * </p>
 *
 * @author mameng
 * @since 2024-03-30
 */
@Service
public class MaterialInAndOutRecordsServiceImpl implements MaterialInAndOutRecordsService {
    @Autowired
    private GMaterialALLOutboundManagementMapper materialALLOutboundManagementMapper;

    @Autowired
    private GMaterialLineSideWarehouseLocationMapper materialLineSideWarehouseLocationMapper;

    @Autowired
    private GMaterialALLInventoryManagementMapper materialALLInventoryManagementMapper;

    @Autowired
    private MaterialAllOutboundItemMapper materialAllOutboundItemMapper;

    @Autowired
    private MaterialInventoryItemMapper materialInventoryItemMapper;

    @Autowired
    private MaterialCpBcpItemsMapper materialCpBcpItemsMapper;

    @Autowired
    private RedisSingleService redisService;

    @Override
    public IPage<MaterialALLOutboundManagement> getPage(MaterialInAndOutRecordReq materialInAndOutRecordReq) {
        List<String> collect1 = new ArrayList<>();
        List<String> collect2 = new ArrayList<>();
        List<String> allIds = new ArrayList<>();
        LambdaQueryWrapper<MaterialAllOutboundItem> materialOutWrapper = Wrappers.<MaterialAllOutboundItem>lambdaQuery();
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode())) {
            materialOutWrapper.like(MaterialAllOutboundItem::getItemCode, materialInAndOutRecordReq.getItemCode());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())) {
            materialOutWrapper.like(MaterialAllOutboundItem::getItemName, materialInAndOutRecordReq.getItemName());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation())) {
            materialOutWrapper.like(MaterialAllOutboundItem::getStorageLocationId, materialInAndOutRecordReq.getStorageLocation());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())) {
            materialOutWrapper.like(MaterialAllOutboundItem::getBatchNumber, materialInAndOutRecordReq.getBatchNumber());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber())) {
            materialOutWrapper.like(MaterialAllOutboundItem::getBarcodeNumber, materialInAndOutRecordReq.getBarcodeNumber());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber())) {
            List<MaterialAllOutboundItem> materialAllOutboundItems = materialAllOutboundItemMapper.selectList(materialOutWrapper);
            collect1 = materialAllOutboundItems.stream().map(MaterialAllOutboundItem::getOutAllId).distinct().collect(Collectors.toList());
            allIds.addAll(collect1);
        }

        LambdaQueryWrapper<MaterialInventoryItem> materialInventoryItemWrapper = Wrappers.<MaterialInventoryItem>lambdaQuery();
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode())) {
            materialInventoryItemWrapper.like(MaterialInventoryItem::getItemCode, materialInAndOutRecordReq.getItemCode());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())) {
            materialInventoryItemWrapper.like(MaterialInventoryItem::getItemName, materialInAndOutRecordReq.getItemName());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation())) {
            materialInventoryItemWrapper.like(MaterialInventoryItem::getStorageLocation, materialInAndOutRecordReq.getStorageLocation());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())) {
            materialInventoryItemWrapper.like(MaterialInventoryItem::getPcNumber, materialInAndOutRecordReq.getBatchNumber());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber())) {
            materialInventoryItemWrapper.like(MaterialInventoryItem::getBarcodeNumber, materialInAndOutRecordReq.getBarcodeNumber());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber())) {
            List<MaterialInventoryItem> materialInventoryItems = materialInventoryItemMapper.selectList(materialInventoryItemWrapper);
            collect2 = materialInventoryItems.stream().map(MaterialInventoryItem::getInventoryNumber).distinct().collect(Collectors.toList());
            allIds.addAll(collect2);
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber())) {
            if (CollectionUtils.isEmpty(collect1) && CollectionUtils.isEmpty(collect2)) {
                IPage<MaterialALLOutboundManagement> page = new Page<>();
                return page;
            }
        }

        materialInAndOutRecordReq.setIds(allIds);

        for (MaterialWareHouseInTableNameCode ele : MaterialWareHouseInTableNameCode.values()) {
            if (materialInAndOutRecordReq.getWarehouseCode().equals(ele.getCode())) {
                materialInAndOutRecordReq.setTableName(ele.getMsg());
                IPage<MaterialALLOutboundManagement> page = materialALLOutboundManagementMapper.getPage(new Page<MaterialALLOutboundManagement>(materialInAndOutRecordReq.getPageNo(), materialInAndOutRecordReq.getPageSize()), materialInAndOutRecordReq);
                if (CollectionUtils.isNotEmpty(page.getRecords())) {
                    List<String> collect = page.getRecords().stream().map(MaterialALLOutboundManagement::getStorageLocation).collect(Collectors.toList());
                    List<MaterialLineSideWarehouseLocation> materialLineSideWarehouseLocations = materialLineSideWarehouseLocationMapper.selectList(Wrappers.<MaterialLineSideWarehouseLocation>lambdaQuery().select(MaterialLineSideWarehouseLocation::getId, MaterialLineSideWarehouseLocation::getLocationName)
                            .in(MaterialLineSideWarehouseLocation::getId, collect));
                    Map<String, String> locationMap = new HashMap<>();
                    for (MaterialLineSideWarehouseLocation materialLineSideWarehouseLocation : materialLineSideWarehouseLocations) {
                        locationMap.put(materialLineSideWarehouseLocation.getId(), materialLineSideWarehouseLocation.getLocationName());
                    }
                    Map<Object, Object> userMap = redisService.hmget(RedisKey.USER_GROUP_TYPE);
                    Map<Object, Object> userDepartMap = redisService.hmget(RedisKey.USER_GROUP_DEPT_TYPE);
                    Map<Object, Object> departNameMap = redisService.hmget(RedisKey.DEPT_GROUP_TYPE);
                    for (MaterialALLOutboundManagement materialALLOutboundManagement : page.getRecords()) {
                        if (locationMap != null) {
                            if (locationMap.get(materialALLOutboundManagement.getStorageLocation()) != null) {
                                materialALLOutboundManagement.setStorageLocation(locationMap.get(materialALLOutboundManagement.getStorageLocation()));
                            }
                        }
                        if (userDepartMap.get(materialALLOutboundManagement.getUsePerson()) != null) {
                            String departId = (String) userDepartMap.get(materialALLOutboundManagement.getUsePerson());
                            if (departNameMap.get(departId) != null) {
                                String departName = (String) departNameMap.get(departId);
                                materialALLOutboundManagement.setDepartName(departName);
                            }
                        }

                        if (userMap.get(materialALLOutboundManagement.getUsePerson()) != null) {
                            String name = (String) userMap.get(materialALLOutboundManagement.getUsePerson());
                            materialALLOutboundManagement.setUsePerson(name);
                        }
                        if (StringUtils.isNotEmpty(materialALLOutboundManagement.getSupplier())) {
                            String supplierName = materialALLInventoryManagementMapper.getSupplierName(materialALLOutboundManagement.getSupplier());
                            if (StringUtils.isNotEmpty(supplierName)) {
                                materialALLOutboundManagement.setSupplier(supplierName);
                            }
                        }
                    }

                }
                return page;
            }
        }
        return null;
    }

    @Override
    public IPage<MaterialCPProductsInInfo> getCPPageList(MaterialInAndOutRecordReq materialInAndOutRecordReq) {

        List<String> allIds = new ArrayList<>();
        List<String> collectCpList = new ArrayList<>();
        LambdaQueryWrapper<MaterialCpBcpItems> materialOutWrapper = Wrappers.<MaterialCpBcpItems>lambdaQuery();
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode())) {
            materialOutWrapper.like(MaterialCpBcpItems::getItemCode, materialInAndOutRecordReq.getItemCode());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())) {
            materialOutWrapper.like(MaterialCpBcpItems::getItemName, materialInAndOutRecordReq.getItemName());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation())) {
            materialOutWrapper.like(MaterialCpBcpItems::getStorageLocationId, materialInAndOutRecordReq.getStorageLocation());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())) {
            materialOutWrapper.like(MaterialCpBcpItems::getBatchNumber, materialInAndOutRecordReq.getBatchNumber());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getATypeShelf())) {
            materialOutWrapper.like(MaterialCpBcpItems::getATypeShelf, materialInAndOutRecordReq.getATypeShelf());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getSpecificationModel())) {
            materialOutWrapper.like(MaterialCpBcpItems::getSpecification, materialInAndOutRecordReq.getSpecificationModel());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getModelGrade())) {
            materialOutWrapper.like(MaterialCpBcpItems::getModelGrade, materialInAndOutRecordReq.getModelGrade());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getATypeShelf())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getSpecificationModel())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getModelGrade())) {
            List<MaterialCpBcpItems> materialAllOutboundItems = materialCpBcpItemsMapper.selectList(materialOutWrapper);
            collectCpList = materialAllOutboundItems.stream().map(MaterialCpBcpItems::getCpBcpId).distinct().collect(Collectors.toList());
            allIds.addAll(collectCpList);
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getATypeShelf())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getSpecificationModel())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getModelGrade())) {
            if (CollectionUtils.isEmpty(collectCpList)) {
                IPage<MaterialCPProductsInInfo> page = new Page<>();
                return page;
            }

        }
        materialInAndOutRecordReq.setIds(allIds);
        Page<MaterialCPProductsInInfo> cpPageList = materialALLOutboundManagementMapper.
                getCPPageList(new Page<>(materialInAndOutRecordReq.getPageNo(),
                        materialInAndOutRecordReq.getPageSize()), materialInAndOutRecordReq);
        if (CollectionUtils.isNotEmpty(cpPageList.getRecords())) {
            List<String> collect = cpPageList.getRecords().stream().map(MaterialCPProductsInInfo::getStorageLocation).collect(Collectors.toList());
            List<MaterialLineSideWarehouseLocation> materialLineSideWarehouseLocations = materialLineSideWarehouseLocationMapper.selectList(Wrappers.<MaterialLineSideWarehouseLocation>lambdaQuery().select(MaterialLineSideWarehouseLocation::getId, MaterialLineSideWarehouseLocation::getLocationName)
                    .in(MaterialLineSideWarehouseLocation::getId, collect));
            Map<String, String> locationMap = new HashMap<>();
            for (MaterialLineSideWarehouseLocation materialLineSideWarehouseLocation : materialLineSideWarehouseLocations) {
                locationMap.put(materialLineSideWarehouseLocation.getId(), materialLineSideWarehouseLocation.getLocationName());
            }
            if (locationMap != null) {
                for (MaterialCPProductsInInfo materialCPProductsInInfo : cpPageList.getRecords()) {
                    if (locationMap.get(materialCPProductsInInfo.getStorageLocation()) != null) {
                        materialCPProductsInInfo.setStorageLocation(locationMap.get(materialCPProductsInInfo.getStorageLocation()));
                    }
                }
            }

        }
        return cpPageList;
    }

    @Override
    public IPage<MaterialRecordsDTO> getRQPageList(MaterialRecordsReq materialRecordsReq) {
        return materialALLOutboundManagementMapper.
                getRQPageList(new Page<>(materialRecordsReq.getPageNo(),
                        materialRecordsReq.getPageSize()), materialRecordsReq);
    }

    @Autowired
    private MaterialBcpProductsInInfoMapper materialBcpProductsInInfoMapper;

    @Autowired
    private MaterialCPProductsInInfoMapper materialCPProductsInInfoMapper;

    @Autowired
    private MaterialBcpProductsOutMapper materialBcpProductsOutMapper;

    @Autowired
    private MaterialCPProductsOutMapper materialCPProductsOutMapper;


    @Override
    public ResultBody rqGetOneByNumber(String number) {
        MaterialBcpProductsInInfo materialBcpProductsInInfo = materialBcpProductsInInfoMapper.selectOne(Wrappers.<MaterialBcpProductsInInfo>lambdaQuery().eq(MaterialBcpProductsInInfo::getInStorageOrderNo, number));
        if (materialBcpProductsInInfo != null) {
            List<MaterialCpBcpItems> materialCpBcpItemsList = materialCpBcpItemsMapper.selectList(Wrappers.<MaterialCpBcpItems>lambdaQuery().eq(MaterialCpBcpItems::getCpBcpId, materialBcpProductsInInfo.getId()));
            materialBcpProductsInInfo.setMaterialCpBcpItemsList(materialCpBcpItemsList);
            return ResultBody.success(materialBcpProductsInInfo);
        }
        MaterialCPProductsInInfo materialCPProductsInInfo = materialCPProductsInInfoMapper.selectOne(Wrappers.<MaterialCPProductsInInfo>lambdaQuery().eq(MaterialCPProductsInInfo::getInStorageOrderNo, number));
        if (materialCPProductsInInfo != null) {
            List<MaterialCpBcpItems> materialCpBcpItemsList = materialCpBcpItemsMapper.selectList(Wrappers.<MaterialCpBcpItems>lambdaQuery().eq(MaterialCpBcpItems::getCpBcpId, materialCPProductsInInfo.getId()));
            materialCPProductsInInfo.setMaterialCpBcpItemsList(materialCpBcpItemsList);
            return ResultBody.success(materialCPProductsInInfo);
        }

        MaterialBcpProductsOut materialBcpProductsOut = materialBcpProductsOutMapper.selectOne(Wrappers.<MaterialBcpProductsOut>lambdaQuery().eq(MaterialBcpProductsOut::getOutStorageOrderNo, number));
        if (materialBcpProductsOut != null) {
            List<MaterialCpBcpItems> materialCpBcpItemsList = materialCpBcpItemsMapper.selectList(Wrappers.<MaterialCpBcpItems>lambdaQuery().eq(MaterialCpBcpItems::getCpBcpId, materialBcpProductsOut.getId()));
            materialBcpProductsOut.setMaterialCpBcpItemsList(materialCpBcpItemsList);
            return ResultBody.success(materialBcpProductsOut);
        }
        MaterialCPProductsOut materialCPProductsOut = materialCPProductsOutMapper.selectOne(Wrappers.<MaterialCPProductsOut>lambdaQuery().eq(MaterialCPProductsOut::getOutStorageOrderNo, number));
        if (materialCPProductsOut != null) {
            List<MaterialCpBcpItems> materialCpBcpItemsList = materialCpBcpItemsMapper.selectList(Wrappers.<MaterialCpBcpItems>lambdaQuery().eq(MaterialCpBcpItems::getCpBcpId, materialCPProductsOut.getId()));
            materialCPProductsOut.setMaterialCpBcpItemsList(materialCpBcpItemsList);
            return ResultBody.success(materialCPProductsOut);
        }
        return null;
    }

    @Override
    public IPage<MaterialBcpProductsInInfo> getBCPPageList(MaterialInAndOutRecordReq materialInAndOutRecordReq) {

        List<String> allIds = new ArrayList<>();
        List<String> collectCpList = new ArrayList<>();
        LambdaQueryWrapper<MaterialCpBcpItems> materialOutWrapper = Wrappers.<MaterialCpBcpItems>lambdaQuery();
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode())) {
            materialOutWrapper.like(MaterialCpBcpItems::getItemCode, materialInAndOutRecordReq.getItemCode());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())) {
            materialOutWrapper.like(MaterialCpBcpItems::getItemName, materialInAndOutRecordReq.getItemName());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation())) {
            materialOutWrapper.like(MaterialCpBcpItems::getStorageLocationId, materialInAndOutRecordReq.getStorageLocation());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())) {
            materialOutWrapper.like(MaterialCpBcpItems::getBatchNumber, materialInAndOutRecordReq.getBatchNumber());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getATypeShelf())) {
            materialOutWrapper.like(MaterialCpBcpItems::getATypeShelf, materialInAndOutRecordReq.getATypeShelf());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getSpecificationModel())) {
            materialOutWrapper.like(MaterialCpBcpItems::getSpecification, materialInAndOutRecordReq.getSpecificationModel());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getModelGrade())) {
            materialOutWrapper.like(MaterialCpBcpItems::getModelGrade, materialInAndOutRecordReq.getModelGrade());
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getATypeShelf())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getSpecificationModel())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getModelGrade())) {
            List<MaterialCpBcpItems> materialAllOutboundItems = materialCpBcpItemsMapper.selectList(materialOutWrapper);
            collectCpList = materialAllOutboundItems.stream().map(MaterialCpBcpItems::getCpBcpId).distinct().collect(Collectors.toList());
            allIds.addAll(collectCpList);
        }
        if (StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemCode()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getItemName())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getStorageLocation()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBatchNumber())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getBarcodeNumber()) || StringUtils.isNotEmpty(materialInAndOutRecordReq.getATypeShelf())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getSpecificationModel())
                || StringUtils.isNotEmpty(materialInAndOutRecordReq.getModelGrade())) {
            if (CollectionUtils.isEmpty(collectCpList)) {
                IPage<MaterialBcpProductsInInfo> page = new Page<>();
                return page;
            }

        }
        materialInAndOutRecordReq.setIds(allIds);

        Page<MaterialBcpProductsInInfo> bcpPageList = materialALLOutboundManagementMapper.
                getBCPPageList(new Page<>(materialInAndOutRecordReq.getPageNo(),
                        materialInAndOutRecordReq.getPageSize()), materialInAndOutRecordReq);
        if (CollectionUtils.isNotEmpty(bcpPageList.getRecords())) {
            List<String> collect = bcpPageList.getRecords().stream().map(MaterialBcpProductsInInfo::getStorageLocation).collect(Collectors.toList());
            List<MaterialLineSideWarehouseLocation> materialLineSideWarehouseLocations = materialLineSideWarehouseLocationMapper.selectList(Wrappers.<MaterialLineSideWarehouseLocation>lambdaQuery().select(MaterialLineSideWarehouseLocation::getId, MaterialLineSideWarehouseLocation::getLocationName)
                    .in(MaterialLineSideWarehouseLocation::getId, collect));
            Map<String, String> locationMap = new HashMap<>();
            for (MaterialLineSideWarehouseLocation materialLineSideWarehouseLocation : materialLineSideWarehouseLocations) {
                locationMap.put(materialLineSideWarehouseLocation.getId(), materialLineSideWarehouseLocation.getLocationName());
            }
            if (locationMap != null) {
                for (MaterialBcpProductsInInfo materialBcpProductsInInfo : bcpPageList.getRecords()) {
                    if (locationMap.get(materialBcpProductsInInfo.getStorageLocation()) != null) {
                        materialBcpProductsInInfo.setStorageLocation(locationMap.get(materialBcpProductsInInfo.getStorageLocation()));
                    }
                }
            }
        }
        return bcpPageList;
    }
}
